package com.yunyi.user.service.impl;

import com.google.common.collect.Maps;
import com.yunyi.model.company.Company;
import com.yunyi.model.company.SysPost;
import com.yunyi.model.mappers.company.CompanyMapper;
import com.yunyi.model.mappers.company.SysPostMapper;
import com.yunyi.model.mappers.work.TimeShiftMapper;
import com.yunyi.model.work.TimeShift;
import com.yunyi.user.constant.Constant;
import com.yunyi.user.redisSevice.RedisService;
import com.yunyi.user.service.TimeShiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName TimeShiftServiceImpl
 * @Description TODO
 * @Author zhanglei
 * Date 2021/8/18 15:59
 * @Version 1.0
 **/
@Service
public class TimeShiftServiceImpl implements TimeShiftService {
    @Autowired
    private TimeShiftMapper timeShiftMapper;
    @Autowired
    private RedisService redisService;

    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private SysPostMapper sysPostMapper;
    /***
     * @Discription: 班次时间获取
     * @param requestParam
     * @return java.util.List<com.yunyi.model.work.TimeShift>
     * @Author: zhanglei on 2021/8/18 16:00
     */
    @Override
    public Map<String,Object>  getTimeShiftInfos(Map<String, Object> requestParam) throws Exception {
        Map<String,Object> resultMap = Maps.newHashMap();
        //1.获取基本班次信息
        requestParam.putIfAbsent(Constant.STATUS,1);
        List<TimeShift> timeShiftInfos = timeShiftMapper.getTimeShiftInfos(requestParam);
        //2.获取班次剩余名额
        Map<Object, Object> workerNumber = redisService.getWorkerNumber();
        for (Map.Entry<Object, Object> workNum : workerNumber.entrySet()) {
            for (TimeShift timeShiftInfo : timeShiftInfos) {
                if (Integer.valueOf(workNum.getKey().toString()).equals(timeShiftInfo.getType())) {
                    timeShiftInfo.setWorkerNumber(Integer.valueOf(workNum.getValue().toString()));
                }
            }
        }
        //3.小程序 使用 拼接岗位 用人单位
        List<Company> companyInfos = companyMapper.getCompanyInfos(requestParam);
        SysPost sysPost = new SysPost();
        sysPost.setStatus(Constant.NUMBER_0_STR);
        List<SysPost> sysPosts = sysPostMapper.selectPostList(sysPost);
        resultMap.put(Constant.TIME_SHIFT_INFOS,timeShiftInfos);
        resultMap.put(Constant.COMPANY_INFOS,companyInfos);
        resultMap.put(Constant.SYS_POSTS,sysPosts);
        return resultMap;
    }
}